package cn.peach2.topics;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 生产者
 */
public class producer {
    public static final String EXCHANGE_TOPICS_ONE = "EXCHANGE_TOPICS_ONE";

    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("115.159.88.63");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        // 创建交换机
        channel.exchangeDeclare(EXCHANGE_TOPICS_ONE, BuiltinExchangeType.TOPIC);
        /*队列名，钥匙，队列持久化，独占连接，删除队列*/
        channel.basicPublish(EXCHANGE_TOPICS_ONE, "topics.pro", null, "发送消息".getBytes());
        // 消息持久化
        channel.basicPublish(EXCHANGE_TOPICS_ONE, "topics.dsk.out", MessageProperties.PERSISTENT_TEXT_PLAIN, "收到消息".getBytes());
        System.out.println("发送消息");
    }
}
